package com.mxsat.gateway.filter;

import org.springframework.cloud.gateway.filter.GatewayFilter;
import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.stereotype.Component;

@Component
public class TestXxGatewayFilterFactory extends AbstractGatewayFilterFactory<Object> {

	
	@Override
	public GatewayFilter apply(Object config) {
		System.out.println("这里是网关！");
		return (exchange, chain) -> {
              //If you want to build a "pre" filter you need to manipulate the
              //request before calling change.filter  
			ServerHttpRequest.Builder builder = exchange.getRequest().mutate();
              builder.header("GatewayFilter", "PreGatewayFilterFactory success");
              //use builder to manipulate the request
              return chain.filter(exchange.mutate().request(builder.build()).build());
		};
	}

}